package ytdp.careagle.com.ytdp.utils;

import android.util.Log;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.List;

import ytdp.careagle.com.ytdp.entity.ProvinceEntity;

/**
 * Created by admin on 2017/9/13.
 */

public class SerializeableUtils {

    public static void serializeData(List<ProvinceEntity> data, String path) {
        ObjectOutputStream oo = null;
        try {
            oo = new ObjectOutputStream(new FileOutputStream(
                    new File(path)));
            oo.writeObject(data);
        } catch (IOException e) {
            e.printStackTrace();
            Log.e("tag", "序列化失败");
        } finally {
            try {
                oo.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    }

    public static List<ProvinceEntity> deserializeData(String path) {
        ObjectInputStream ois = null;
        List<ProvinceEntity> obj = null;
        try {
            ois = new ObjectInputStream(new FileInputStream(
                    new File(path)));
            obj = (List<ProvinceEntity>) ois.readObject();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                ois.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return obj;
    }

}
